<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8"/>
    <title>call-back</title>
    <script type="text/javascript" src="./jquery.js"></script>
    <script type="text/javascript" src="./sso.js"></script>
</head>
<body>
<script>
    window.onload = function() {
        //url获取code
        let code = getQueryParam('code');
        if(code){
            if(confirm("code换取token")) getToken(code);
        }else{
            toLogin()
        };
    };

    function getToken(code) {
        $.post("http://localhost:18091/token", {
            code: code,
            client_id: "web",
            redirect_uri: "http://pf.com/callback.html"
        }, function (result) {
            if(result.user_name){
                var token = result.access_token;
                document.cookie = "Authorization=Bearer " + token;
                // if(confirm("跳转到原页面")) 
                    window.location = sessionStorage.getItem('visitUri');
            }else{
                alert("获取token失败"+JSON.stringify(result));
            }
        });
    }
</script>
</body>
</html>
